﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class IM_groupChat : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string groupName = Request.QueryString["r"].ToString();//sets the group name
            CS_Code.IMDataContext db = new CS_Code.IMDataContext();

            //gets the group ID
            var getID = (from cr in db.IM_Chat_Rooms
                         orderby cr.uid descending
                         where cr.room_name == groupName
                         select cr.room_ID).FirstOrDefault();

            hfSender.Value = IM.UserName();
            lblTitle.Text = "Group Chat: " + groupName;

            if (getID.HasValue)
            {
                hfRecipient.Value = getID.Value.ToString();

                //sets the buddy list.
                var getBuddyList = (from cr in db.IM_Chat_Rooms
                                    where cr.room_ID == getID
                                    select new { user = IM.UserName(cr.userinRoom) }).Distinct();
                lbUsersInChat.DataSource = getBuddyList;
                lbUsersInChat.DataBind();
            }
            lbUsersInChat.Attributes.Add("ondblclick", "lstDblClicked()");
        }
    }
}
